<?php
class skills extends MX_Controller
{
    private $limit;
    public function __construct()
    {
        parent::__construct();
        $this->limit = 10;
    }
    
    public function index()
    {
        $data = array(
            'title' => 'Skill studio - Kỹ năng',
            'meta_des' => 'Skill studio kỹ năng mềm',
            'meta_key' => 'kill, studio, soft skill, english skill',
            );
        $this->load->view("templates/master_skill", $data);
    }
    
    public function detail($alias = '')
    {
        $this->load->model('Skill_Categories_Model');
        $skillModel = new Skill_Categories_Model();
        $ids = $skillModel->getCategorybyAlias($alias);
        if (empty($ids)) {
            return redirect(base_url());
        }
        $id = $ids->id;
        $result = $skillModel->getCategorybyId($id);
        if (!$result) {
            return redirect(base_url());
        }
        $skillModel->upHit($id);
        $content = $this->load->view('categorys/detail', array('result' => $result), TRUE);
        
        $this->load->model('Skill_Videos_Model');
        $videoModel = new Skill_Videos_Model();
        
        $video_lq = $this->load->view('categorys/video_lq', 
            array(
                'vresult' => $videoModel->getVideo_byCategory($id),
                'mtitle' => $result->title,
                'malias'=> $result->malias,
            ), TRUE);
            
        $cResult = $skillModel->getCategory_ByMenu($result->mid, 0, 15, 1, $id);
        
        $cate_order = $this->load->view('categorys/cate_order', array(
            'cresult' => $cResult,
            'mtitle' => $result->mtitle,
            'malias'=> $result->malias,
            ), TRUE);
        $data = array(
            'content' => $content,
            'video_lq' => $video_lq,
            'cate_order' => $cate_order,
            'title' => $result->title,
            'meta_des' => $result->keyword,
            'meta_key' => $result->description,
            'mid' => $result->mid
            );
        $this->load->view("templates/master_detail", $data);
    }
    
    public function video_comment_ajax($vid = 0, $ofset = 0)
    {
        $this->load->model('Skill_Video_Comments_Model');
        $commentModel = new Skill_Video_Comments_Model();
        
        $result = $commentModel->getComment_byVid($vid, $ofset, $this->limit);

        $this->load->view('videos/comment_ajax', array('result' => $result));
    }
    
    public function video_comment($vid = 0, $ofset = 0)
    {
        $this->load->model('Skill_Video_Comments_Model');
        $commentModel = new Skill_Video_Comments_Model();
        $paging = paging_fo('skills/video_comment_ajax/'.$vid, $commentModel->cTotal($vid), $this->limit, 4);
        $result = $commentModel->getComment_byVid($vid, $ofset, $this->limit);

        return $this->load->view('videos/comment', array(
            'result' => $result,
            'vid' => $vid,
            'paging' => $paging
        ), TRUE);
    }
    
    public function video_detail($alias = '')
    {
        $this->load->model('Skill_Videos_Model');
        $skillModel = new Skill_Videos_Model();
       
        $ids = $skillModel->getVideo_byAlias($alias);
        if (empty($ids)) {
            return redirect(base_url());
        }
        $id = $ids->id;
       
        $result = $skillModel->getVideo_byId($id);
        if (!$result) {
            return redirect(base_url());
        }
       
        $skillModel->upHit($id);
        $content = $this->load->view('categorys/video_detail', array('result' => $result), TRUE);
        
        $this->load->model('Skill_Videos_Model');
        $videoModel = new Skill_Videos_Model();
        $video_lq = $this->load->view('categorys/video_lq', 
            array(
                'vresult' => $videoModel->getVideo_byCategory($result->cid, $id),
                'mtitle' => $result->ctitle,
                'malias'=> $result->malias
            ), TRUE);
            
        $video_comment = $this->video_comment($id);
        $data = array(
            'content' => $content,
            'video_lq' => $video_lq,
            'video_comment' => $video_comment,
            'title' => $result->title,
            'meta_des' => $result->keyword,
            'meta_key' => $result->description,
            'mid' => $result->mid
            );
        $this->load->view("templates/master_detail", $data);
    }
    
    public function softskill($offset = 0)
    {
        $this->load->model('Skill_Categories_Model');
        $skillModel = new Skill_Categories_Model();
        $result = $skillModel->getCategory_ByMenu(1, $offset, $this->limit, 1);
        $paging = paging_fo('ky-nang-mem/chuyende', $skillModel->cTotal(1), $this->limit, 3);
        $breakCrum = '';

        $data = array(
            "content" => $this->load->view("categorys/main", array(
                'result' => $result,
                'paging' => $paging,
                'title' => 'Kỹ năng mềm - Skill studio',
                'meta_des' => 'Skill studio kỹ năng mềm',
                'meta_key' => 'kill, studio, soft skill, english skill',
                ), true), 
            "breakCrum" => $breakCrum);
       
        $this->load->view("templates/master_skill_category", $data);
    }
    
    public function softskill_block()
    {
        $this->load->model('Skill_Categories_Model');
        $skillModel = new Skill_Categories_Model();
        $dataSoft = $skillModel->blockCoursesSoft();
        return $this->load->view('categorys/sblock', array('soft' => $dataSoft));
    }
    
    public function englishkill($offset = 0)
    {
        $this->load->model('Skill_Categories_Model');
        $skillModel = new Skill_Categories_Model();
        $result = $skillModel->getCategory_ByMenu(2, $offset, $this->limit, 1);
        $paging = paging_fo('anh-van/chuyende', $skillModel->cTotal(2), $this->limit, 3);
        $breakCrum = '';

        $data = array(
            "content" => $this->load->view("categorys/english", array(
                'result' => $result,
                'paging' => $paging,
                'title' => 'Tiếng Anh - Skill studio',
                'meta_des' => 'Skill studio kỹ năng mềm',
                'meta_key' => 'kill, studio, soft skill, english skill',
                ), true), 
            "breakCrum" => $breakCrum);
       
        $this->load->view("templates/master_skill_category", $data); 
    }
    
    public function englishskill_block()
    {
        $this->load->model('Skill_Categories_Model');
        $skillModel = new Skill_Categories_Model();
        $dataEnglish = $skillModel->blockCoursesEnglish();
        return $this->load->view('categorys/eblock', array('english' => $dataEnglish));
    }
    
    
    public function popup_display()
    {
        $this->load->model('util/captcha_model');
        $captcha = new Captcha_Model();
        $imgCaptcha = $captcha->captcha_generate();
        $this->load->view('videos/captchaform', array('image' =>  $imgCaptcha));
    }
    
    public function captchasubmit()
    {
        $this->load->model('util/captcha_model');
        $captcha = new Captcha_Model();
        $arr = array();
        if (!$captcha->captcha_check()) {
            $imgCaptcha = $captcha->captcha_generate();
            $arr['success'] = 0;
            $arr['captcha'] = $imgCaptcha;
            echo json_encode($arr);
            exit();
        } else {
            $this->load->model('Skill_Video_Comments_Model');
            $commentModel = new Skill_Video_Comments_Model();
            $commentModel->addComment();
            $arr['success'] = 1;
            echo json_encode($arr);
            exit();
        }        
    }
    
    public function newcomment()
    {
        $this->load->helper('text');
        $this->load->model('Skill_Video_Comments_Model');
        $cModel = new Skill_Video_Comments_Model();
        $result = $cModel->newVideoComment();
        $this->load->view('videos/new_comment', array('result' => $result));
    }
    
    public function topskill($alias = '')
    {
        echo '<h2> function is building... </h2>';
    }
}